package com.peng.leetcode.jump;

/**
 * Jump
 *
 * @author: lupeng6
 * @create: 2020/11/28 20:45
 */
public class Jump {


    public static void main(String[] args) {
        int[] d = {2, 3, 1, 1, 4};
//        int[] d = {1};
        System.out.println(new Solution().jump(d));
    }

    static class Solution {
        public int jump(int[] nums) {
            int step = 0;
            int rightMost = 0;
            int stepEnd = 0;
            for (int i = 0; i < nums.length - 1; i++) {
                int num = nums[i];
                rightMost = Math.max(rightMost, i + num);
                if (i == stepEnd) {
                    stepEnd = rightMost;
                    step++;
                }
            }
            return step;
        }
    }
}
